Welcome to the SAP ABAP Tutorials. The objective of these tutorials is to get an in-depth understanding of SAP ABAP. The tutorial starts with an overview of SAP ABAP. In addition to these tutorials, we will also cover common issues, Interview questions, and How To’s of SAP ABAP.
ABAP (Advanced Business Application Programming) is a programming language for developing applications for the SAP R/3 system, a widely-installed business application subsystem. The latest version, ABAP Objects, is object-oriented programming. SAP will run applications written using ABAP/4, the earlier ABAP version, as well as applications using ABAP Objects. SAP's original business model for R/3 was developed before the idea of an object-oriented model was widespread. The transition to the object-oriented model reflects increased customer demand for it. ABAP Objects uses a single inheritance model and full support for object features such as encapsulation, polymorphism, and persistence. ABAP language syntax
ABAP is not case sensitive.
Every statement begins with a keyword and ends with a period. ( WRITE is the keyword to print on screen )
WRITE 'Hello World!'.
Chained statements. If consecutive statements have identical parts at the beginning, then ABAP allows you to chain these statements into a single statement. First, write the identical part once and then place a colon (:). Then write the remaining parts of the individual statements separated by commas. Normal Statements:
WRITE 'Hello'. WRITE 'ABAP'.
Chained Statement:
WRITE: 'Hello', 'ABAP'.
Comments. If you want to make the entire line as a comment, then enter an asterisk (*) at the beginning of the line.
* This is a comment line
If you want to make a part of the line as a comment, then enter a double quote (“) before the comment.
WRITE 'COMMENT'. "Start of comment Create an instance of a class that implements a certain interface, but you won’t know the name of the class you want to create until run time. In Java or .NET you would have used the reflection mechanism, but can you handle this case in ABAP Here’s a short code snippet showing how: DATA: iv_classname TYPE social name. DATA: iv_interface TYPE REF TO IF_INTERFACE_NAME. DATA: gr_error TYPE REF TO cx_dynamic_check. DATA: gv_message TYPE string. iv_classname = 'CL_CLASSNAME'. TRY. CREATE OBJECT iv_interface TYPE (iv_classname). CATCH cx_sy_create_object_error INTO gr_error. gv_message = gr_error->get_text( ). WRITE /1 gv_message. CATCH cx_sy_dyn_call_param_missing INTO gr_error. gv_message = gr_error->get_text( ). WRITE /1 gv_message. ENDTRY. Let’s have a look at the code. In the first four rows, you define several variables of data types. iv_classname holds the name of the class (that’s the name which will be known only in run time) iob_object – a reference to an interface that the class you’ll instantiate implements. The other two variables are for error handling purposes. Now, you use the CREATE OBJECT ABAP statement. CREATE OBJECT iv_interface TYPE (iv_classname). Note that had you known the class name during compile time, you could use the following statement: CREATE OBJECT iv_interface TYPE CLASSNAME. The difference? No parenthesis, plus you give the class name instead of a string containing the class name. Let’s move on. In case the class does not exist on the system you’re running (or you provided a wrong class name), you’ll get the exception CX_SY_CREATE_OBJECT_ERROR, saying that the class you’re trying to instantiate couldn’t be found. In case there are missing parameters, you will get aCX_SY_DYN_CALL_PARAM_MISSING exception. CREATE OBJECT iv_interface TYPE (iv_classname) EXPORTING param1 = value1 param2 = value2. You now know a little bit about dynamically instantiating objects in your code – a great way to implement dynamic and extensible factory methods.
If you would like to become an SAP ABAP certified professional, then visit Tekslate - A Global online training platform:"SAP ABAP Training and Certification Course". This course will help you to achieve excellence in this domain.
Parameters statements are almost the same as data statements but it used for the user inputs. The variables declared using parameters statement are known as parameters and these will be displayed on the selection screen while running the program. The user needs to enter or modify the values there and again continue the program execution. The syntax of parameters statement is
Parameter's statement has a lot of additions for use.
Data Types: Data statement is used for defining variables in our ABAP programming. The syntax of data statement:
After watching different data types used in ABAP we can see the usage of data statements with some examples. Character data types used in ABAP
Sample data statement declarations Data x. (Here variable x will be treated as a character because the character is the default data type) data x(2) type c . (Here variable x will be treated as a character with length 2) data x type I value 100. (Here variable x will be treated as the integer with default value 100) data x type d value 20110112. (Here variable x will be treated as date with the specified default value) By using like addition with data statement all the properties like data type, length of the previously defined variable will be assigned to the new variable. Data x1(2) type c. Data x2 like x1.
Related Article:-SAP SD Tutorials
You liked the article?
Like: 0
Vote for difficulty
Current difficulty (Avg): Medium
TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.